﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace CoreApp.Web.Controllers
{
    public class ParentController : Controller
    {
        private int _userId = 0;

        public int GetUserId()
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                //登陆时，规定用户id存储到ClaimTypes.NameIdentifier
                var NameIdentifier = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
                int.TryParse(NameIdentifier, out _userId);
            }
            return _userId;
        }
    }
}